﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ARS.Control.Custom.Entity.Forms
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:CharForm runat=server></{0}:CharForm>")]
    public class CharForm : Form
    {

        protected string inputType;

        public CharForm(string inputType = "text")
        {
            this.inputType = inputType;
        }

        protected virtual string GetInputTextHtml()
        {
            return string.Format(base.GetTrHtml(),string.Format("<input type=\"{2}\" name=\"{0}\" value='{1}' {{0}}>", base.Field.Html_Control_Name,
                base.Field.Value,this.inputType));
             
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            base.RenderContents(output);
            //string tr = string.Format("<input type=\"text\" name=\"{0}\" value={1}>",base.Field.Html_Control_Name,base.Field.Value);
            string html = null;
            if (base.Field.IsAllowBlank == false)
            {
                html = " reg='.+' tip='不能为空'";
            }
            else
            {
                if (this.Field.Tip == null)
                {
                    html = string.Format("IsAllowBlank=true  reg='{0}'", this.Field.RegexStr);
                }
                else
                {
                    html = string.Format("IsAllowBlank=true  reg='{0}' tip='{1}'", this.Field.RegexStr, this.Field.Tip);                    
                }
            }
            output.Write(string.Format(this.GetInputTextHtml(),html));
        }
    }
}
